DECLARE @L0 uniqueidentifier,@L2 uniqueidentifier,@DN nvarchar(260),@L3
 uniqueidentifier;

SET @L0='00000000-0000-0000-0000-000000000000';
SET @L2='91ED7715-7EE3-4304-A825-89F9850B464A'
SET @DN=N'rollup/test1/Lists/TaskList';
SET @L3='0CBBE27C-E6AD-43BE-8CA9-5DA426CDAED7';

WITH InternalTable As 
(
SELECT TOP 101 t1.[Type] AS c0,
         UserData.[tp_ContentTypeId],
         UserData.[tp_ID],
         UserData.[tp_IsCurrentVersion],
         t1.[TimeCreated] AS c4,
         UserData.[tp_CopySource],
         UserData.[tp_Created],
         CASE
           WHEN DATALENGTH(t1.DirName) = 0 THEN t1.LeafName
           WHEN DATALENGTH(t1.LeafName) = 0 THEN t1.DirName
           ELSE t1.DirName + N' / ' + t1.LeafName
                           END AS c1,
                           UserData.[tp_ModerationStatus],
                           UserData.[tp_Level],
                           UserData.[tp_SiteId],
                           UserData.[tp_LeafName],
                           UserData.[tp_CalculatedVersion],
                           UserData.[nvarchar1],
                           UserData.[tp_HasCopyDestinations],
                           UserData.[int4],
                           UserData.[tp_DirName],
                           t1.[LeafName]                     AS c3,
                           UserData.[nvarchar2],
                           t1.[DirName]                      AS c5,
                           UserData.[tp_ContentType],
                           UserData.[tp_DeleteTransactionId],
                           t1.[ScopeId]                      AS c2,
                           UserData.[tp_UIVersion]
          FROM     UserData
                   LEFT OUTER LOOP JOIN Docs AS t1 WITH (NOLOCK)
                     ON (1 = 1
                         AND UserData.[tp_RowOrdinal] = 0
                         AND t1.SiteId = UserData.tp_SiteId
                         AND t1.SiteId = @L2
                         AND t1.DirName = UserData.tp_DirName
                         AND t1.LeafName = UserData.tp_LeafName
                         AND t1.Level = UserData.tp_Level
                         AND t1.IsCurrentVersion = 1
                         AND (1 = 1))
          WHERE    UserData.tp_ListID = @L3
                   AND ((UserData.tp_IsCurrent = 1))
                   AND UserData.tp_SiteId = @L2
                   AND (UserData.tp_DirName = @DN)
                   AND UserData.tp_RowOrdinal = 0
                   AND (t1.SiteId = @L2
                        AND (t1.DirName = @DN))
          ORDER BY UserData.[tp_ID] Asc
);

SELECT   DISTINCT t3.*,
                  t4.[tp_Ordinal],
                  t2.[tp_ID]      AS c6,
                  t5.[nvarchar6]  AS c6c7
FROM  InternalTable AS t3
         LEFT OUTER JOIN UserDataJunctions AS t4
           ON t3.[tp_SiteId] = t4.[tp_SiteId]
              AND t3.[tp_DeleteTransactionId] = t4.[tp_DeleteTransactionId]
              AND t3.[tp_IsCurrentVersion] = t4.[tp_IsCurrentVersion]
              AND t3.[tp_DirName] = t4.[tp_DirName]
              AND t3.[tp_LeafName] = t4.[tp_LeafName]
              AND t3.[tp_CalculatedVersion] = t4.[tp_CalculatedVersion]
              AND t3.[tp_Level] = t4.[tp_Level]
         LEFT OUTER JOIN UserDataJunctions AS t2
           ON t3.[tp_SiteId] = t2.[tp_SiteId]
              AND t3.[tp_DeleteTransactionId] = t2.[tp_DeleteTransactionId]
              AND t3.[tp_IsCurrentVersion] = t2.[tp_IsCurrentVersion]
              AND t3.[tp_DirName] = t2.[tp_DirName]
              AND t3.[tp_LeafName] = t2.[tp_LeafName]
              AND t3.[tp_CalculatedVersion] = t2.[tp_CalculatedVersion]
              AND t3.[tp_Level] = t2.[tp_Level]
              AND t4.[tp_Ordinal] = t2.[tp_Ordinal]
              AND t2.[tp_FieldId] = ' {fdda84e2 - 205c - 42dc - 9f8a -
               16264110a70e}' LEFT OUTER JOIN AllUserData AS t5 WITH (NOLOCK,
                INDEX = AllUserData_PK) ON (t5.[tp_ListId] = @L3 AND t5.[tp_Id]
                 = t2.[tp_ID] AND t5.[tp_RowOrdinal] = 0 AND
                  t5.[tp_CalculatedVersion] = 0 AND t5.[tp_DeleteTransactionId]
                   = 0x)
  ORDER BY t3.tp_ID Asc,
           t4.[tp_Ordinal]
  OPTION (FORCE ORDER)
